home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / syscall / RCS / Fs_ReadVector.c,v < prev    next >
Encoding:
Text File  |  1991-12-09  |  4.5 KB  |  223 lines

  1. head     1.5;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.5.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.5
  10. date     88.07.29.17.08.24;  author ouster;  state Exp;
  11. branches 1.5.1.1;
  12. next     1.4;
  13.  
  14. 1.4
  15. date     88.07.25.11.15.19;  author ouster;  state Exp;
  16. branches ;
  17. next     1.3;
  18.  
  19. 1.3
  20. date     88.07.01.14.01.51;  author ouster;  state Exp;
  21. branches ;
  22. next     1.2;
  23.  
  24. 1.2
  25. date     88.06.21.11.16.05;  author ouster;  state Exp;
  26. branches ;
  27. next     1.1;
  28.  
  29. 1.1
  30. date     88.06.19.14.29.12;  author ouster;  state Exp;
  31. branches ;
  32. next     ;
  33.  
  34. 1.5.1.1
  35. date     91.12.08.17.05.02;  author kupfer;  state Exp;
  36. branches ;
  37. next     ;
  38.  
  39.  
  40. desc
  41. @@
  42.  
  43.  
  44. 1.5
  45. log
  46. @Lint.
  47. @
  48. text
  49. @/* 
  50.  * Fs_ReadVector.c --
  51.  *
  52.  *    Source code for the Fs_ReadVector library procedure.
  53.  *
  54.  * Copyright 1988 Regents of the University of California
  55.  * Permission to use, copy, modify, and distribute this
  56.  * software and its documentation for any purpose and without
  57.  * fee is hereby granted, provided that the above copyright
  58.  * notice appear in all copies.  The University of California
  59.  * makes no representations about the suitability of this
  60.  * software for any purpose.  It is provided "as is" without
  61.  * express or implied warranty.
  62.  */
  63.  
  64. #ifndef lint
  65. static char rcsid[] = "$Header: Fs_ReadVector.c,v 1.4 88/07/25 11:15:19 ouster Exp $ SPRITE (Berkeley)";
  66. #endif not lint
  67.  
  68. #include <sprite.h>
  69. #include <fs.h>
  70. #include <status.h>
  71. #include <stdlib.h>
  72.  
  73. /*
  74.  *----------------------------------------------------------------------
  75.  *
  76.  * Fs_ReadVector --
  77.  *
  78.  *      The "normal" Fs_ReadVector routine for user code.  Read from the file
  79.  *      indicated by the stream ID into the buffers described in vectorArray.
  80.  *    The vectorArray indicates how much data to read, and amtReadPtr 
  81.  *    is an output parameter that indicates how much data were read.  
  82.  *    A length of zero means end-of-file.
  83.  *
  84.  *    Restarting from a signal is automatically handled by Fs_Read.
  85.  *
  86.  * Results:
  87.  *    Result from Fs_Read.
  88.  *
  89.  * Side effects:
  90.  *    See Fs_Read.
  91.  *
  92.  *----------------------------------------------------------------------
  93.  */
  94.  
  95. ReturnStatus
  96. Fs_ReadVector(streamID, numVectors, vectorArray, amtReadPtr)
  97.     int        streamID;    /* The user's index into its open file list. */
  98.     int        numVectors;    /* The # of vectors in userVectorArray. */
  99.     Fs_IOVector    vectorArray[];    /* The vectors defining where and how much to
  100.                  * read. */
  101.     int        *amtReadPtr;     /* The amount of bytes actually read. */
  102. {
  103.     register int     i;
  104.     register Fs_IOVector *vectorPtr;
  105.     register int    bufSize;
  106.     Address        buffer;
  107.     Address        ptr;
  108.     ReturnStatus    status;
  109.  
  110.     /*
  111.      * Calculate the total number of bytes to be read.
  112.      */
  113.     bufSize = 0;
  114.     for (i = 0, vectorPtr = vectorArray; i < numVectors; i++, vectorPtr++) {
  115.     if (vectorPtr->bufSize < 0) {
  116.         return SYS_INVALID_ARG;
  117.     }
  118.     bufSize += vectorPtr->bufSize;
  119.     }
  120.  
  121.     buffer = (Address) malloc((unsigned) bufSize);
  122.     status = Fs_Read(streamID, bufSize, buffer, amtReadPtr);
  123.  
  124.     if (status == SUCCESS) {
  125.     register int copyAmount;
  126.  
  127.     bufSize = *amtReadPtr;
  128.  
  129.     /*
  130.      * Copy the data to the individual buffers specified in the vectorArray.
  131.      */
  132.     ptr = buffer;
  133.     for (i = 0, vectorPtr = vectorArray;
  134.         (i < numVectors) && (bufSize > 0); 
  135.         i++, vectorPtr++) {
  136.  
  137.         if (bufSize < vectorPtr->bufSize) {
  138.         copyAmount = bufSize;
  139.         vectorPtr->bufSize = bufSize;
  140.         } else {
  141.         copyAmount = vectorPtr->bufSize;
  142.         }
  143.         bcopy(ptr, vectorPtr->buffer, copyAmount);
  144.         ptr += copyAmount;
  145.         bufSize -= copyAmount;
  146.     }
  147.     }
  148.     free((char *) buffer);
  149.     return(status);
  150. }
  151. @
  152.  
  153.  
  154. 1.5.1.1
  155. log
  156. @Initial branch for Sprite server.
  157. @
  158. text
  159. @d17 1
  160. a17 1
  161. static char rcsid[] = "$Header: /sprite/src/lib/c/syscall/RCS/Fs_ReadVector.c,v 1.5 88/07/29 17:08:24 ouster Exp $ SPRITE (Berkeley)";
  162. @
  163.  
  164.  
  165. 1.4
  166. log
  167. @Lint.
  168. @
  169. text
  170. @d17 1
  171. a17 1
  172. static char rcsid[] = "$Header: Fs_ReadVector.c,v 1.3 88/07/01 14:01:51 ouster Exp $ SPRITE (Berkeley)";
  173. d73 1
  174. a73 1
  175.     buffer = (Address) malloc(bufSize);
  176. @
  177.  
  178.  
  179. 1.3
  180. log
  181. @Remove calls to Stat_Error:  they aren't needed anymore.
  182. @
  183. text
  184. @d17 1
  185. a17 1
  186. static char rcsid[] = "$Header: Fs_ReadVector.c,v 1.2 88/06/21 11:16:05 ouster Exp $ SPRITE (Berkeley)";
  187. d23 1
  188. a23 7
  189.  
  190. /*
  191.  * Library imports:
  192.  */
  193.  
  194. extern char *malloc();
  195.  
  196. @
  197.  
  198.  
  199. 1.2
  200. log
  201. @Need to include status.h
  202. @
  203. text
  204. @d17 1
  205. a17 1
  206. static char rcsid[] = "$Header: Fs_ReadVector.c,v 1.1 88/06/19 14:29:12 ouster Exp $ SPRITE (Berkeley)";
  207. d74 1
  208. a74 1
  209.         return Stat_Error(SYS_INVALID_ARG);
  210. @
  211.  
  212.  
  213. 1.1
  214. log
  215. @Initial revision
  216. @
  217. text
  218. @d17 1
  219. a17 1
  220. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  221. d22 1
  222. @
  223.